/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.beans.admin;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import manager.CasteManager;
import model.admin.Castes;

/**
 *
 * @author Danh
 */
@ManagedBean
@RequestScoped
public class CasteBean {

    private int casteID;
    private String cateName;
    private boolean catestatus;

    public void reset() {
        cateName = "";
        catestatus = false;
    }

    public int getCateID() {
        return casteID;
    }

    public void setCateID(int cateID) {
        this.casteID = cateID;
    }

    public String getCateName() {
        return cateName;
    }

    public void setCateName(String cateName) {
        this.cateName = cateName;
    }

    public boolean isCatestatus() {
        return catestatus;
    }

    public void setCatestatus(boolean catestatus) {
        this.catestatus = catestatus;
    }

    public List<Castes> loadCaste() {
        CasteManager mana = new CasteManager();
        return mana.getCates();
    }

    public String editAction(int id, String name, boolean status) {
        this.casteID = id;
        this.cateName = name;
        this.catestatus = status;
        return "updateCaste.xhtml";
    }

    public void insertCaste() {
        Castes c = new Castes(this.cateName, this.catestatus);
        CasteManager mana = new CasteManager();
        boolean result = mana.insertCates(c);
        if (result) {
           loadCaste();
        }
    }

    public String deleteCountry(int id) {
        CasteManager mana = new CasteManager();
        boolean deleteCountry = mana.deleteCate(id);
        if (deleteCountry) {
            return "casteManager.xhtml?faces-redirect=true";
        }
        return "";
    }

    public String sua() {
       Castes c=new Castes(this.casteID, this.cateName, this.catestatus);
      CasteManager mana = new CasteManager();
        mana.update(c);
        return "casteManager.xhtml?faces-redirect=true";

    }

    public CasteBean() {
    }
}
